const { Article } = require('../../../model/article');
const moment = require('moment')

module.exports = (req, res) => {
  const { id } = req.body
  let body = {}
  if (req.body.state === 1) {
      body.publishDate = moment().format('YYYY-MM-DD HH:mm:ss')
  }
  Article.updateOne({_id: id}, {
    ...req.body,
    ...body
  }, (err, row) => {
    if(!err) {
      res.json({
        message: '更新成功!'
      })
    } else {
      res.status(403)
      res.json({
        log: err,
        message: '更新失败！'
      })
    }
  })
}